/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaapplication4.view;


import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.FlowLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import javaapplication4.controller.AbstractController;
import javaapplication4.model.observer.Observer;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JSeparator;
import javax.swing.JTextField;
/**
 *
 * @author mathieubakrim
 */
public class AdressBookView extends JFrame implements Observer{
    private JPanel container = new JPanel();
    
    
    
     private JMenuBar menuBar = new JMenuBar();
     private JMenu file = new JMenu("File");
     private JMenu services = new JMenu("Services");
     
     private JMenuItem quit = new JMenuItem("Quit");
     private JMenuItem createContact = new JMenuItem("Create a contact");
     private JMenuItem alphaList = new JMenuItem("Alpha contacts list");
    private AbstractController controller;
    
    public AdressBookView(AbstractController controller){
        this.setSize(450, 470);
        this.setTitle("Adress Book");
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        this.setLocationRelativeTo(null);
        this.setResizable(false);
        initComposant();
        this.controller = controller;
        this.setContentPane(container);
        this.setVisible(true);
    }

    private void initComposant() {
        //Menu
        file.addSeparator();
        file.add(quit);
        services.add(createContact);
        services.add(alphaList);
        
        quit.addActionListener(new AdressBookView.QuitListener());
        createContact.addActionListener(new AdressBookView.CreateContactListener());
        alphaList.addActionListener(new AdressBookView.AlphaListListener());
        
        menuBar.add(file);
        menuBar.add(services);
        setJMenuBar(menuBar);
        setVisible(true);
        
        
        JPanel basic = new JPanel();
        basic.setLayout(new BoxLayout(basic, BoxLayout.Y_AXIS));
        add(basic);
       
        JPanel topPanel = new JPanel(new BorderLayout(0, 0));
        //topPanel.setMaximumSize(new Dimension(450, 0));
        JLabel title = new JLabel("Home");
        title.setBorder(BorderFactory.createEmptyBorder(0, 25, 0, 0));
        topPanel.add(title);
        
        JSeparator separator = new JSeparator();
        separator.setForeground(Color.gray);

        topPanel.add(separator, BorderLayout.SOUTH);

        basic.add(topPanel);
        
        
        JPanel form = new JPanel();     
        
        form.setBorder(BorderFactory.createEmptyBorder(8, 2, 5,5));
        form.setLayout(new GridLayout(8,2,5,5));
        
      
        
        
        basic.add(form);
        
        JPanel bottom = new JPanel(new FlowLayout(FlowLayout.RIGHT));

       
        
        basic.add(bottom);
        
        container.add(basic);
        
      
        
    } 

    @Override
    public void update(String str) {
        throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
    }
    
   
    class QuitListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "Have a nice day :)");
            System.exit(0);
        }
    }
    class CreateContactListener implements ActionListener {

        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(null, "You will create a contact soon:)");
            controller.showContactForm();
        }
    }

    class AlphaListListener implements ActionListener {
        public void actionPerformed(ActionEvent e){
            JOptionPane.showMessageDialog(null, "You will have your alphabetical contacts list soon");
            controller.showAlphaList();
        } //
    }
}
